package ui.map 
{
	import com.gaiaframework.api.Gaia;
	import com.gaiaframework.assets.BitmapSpriteAsset;
	import com.lextalkington.parallax.ParallaxEngine;
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import pages.Pages;
	
	/**
	 * ...
	 * @author usual
	 */
	public class InertiaBehindMask extends MovieClip 
	{
		private var _bitmapSpriteAsset:BitmapSpriteAsset;
		private var _displayObjectAsset:DisplayObject;
		private var _mask:Sprite;
		private var _pE:ParallaxEngine;
		
		public function InertiaBehindMask(asset:String) 
		{
			//var pattern:RegExp = /-/g; // le g pour spécifier que l'on veut remplacer  toutes les occurrences :)
			//asset = asset.replace(pattern,"_");
			//trace("[InertiaBehindMask.InertiaBehindMask] ", Gaia.api.getPage(Pages.HOME).assets[asset]);
			
			_bitmapSpriteAsset  = Gaia.api.getPage(Pages.HOME).assets[asset];
			_bitmapSpriteAsset.smoothing = _bitmapSpriteAsset.visible = true;
			_displayObjectAsset = _bitmapSpriteAsset.container;
			addEventListener(Event.ADDED_TO_STAGE, build);
		}
		
		private function build(e:Event):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, build);
			//_displayObjectAsset.y = 30;
			var sh:int = 400;
			var sw:int = 400;
			_pE = new ParallaxEngine(sw,sh, .05, ParallaxEngine.X_AXIS);
			_pE.addPlate(_displayObjectAsset);
			addChild(_pE);
			//resize();
		}
		
		public function stopEffect():void 
		{
			if(_pE)_pE.pause();
		}
		
		public function startEffect():void 
		{
			if(_pE)_pE.start();
		}
		
		public function dispose():void 
		{
			if(_pE)_pE.dispose();
		}
		
		public function resize():void 
		{
			trace("[InertiaBehindMask.resize] ");
			_pE.pause();
			var sh:int = stage.stageHeight
			//_pE._height = int(_displayObjectAsset.height);
			_pE.start();
		}		
	}

}